﻿/*
 * Created by: Ahmedzhanov Nail,400,438534,,J2EE
 * Created: Sunday, February 25, 2007
 */

using System;
using Edge.Business.Security;
using Edge.Common.Services;
using Shop.Business.Domain.Orders;
using Shop.Business.Domain.Pricing;

namespace Shop.Business.Domain.Orders.Logic
{
    public abstract class BaseOrderOperation : IOperation
    {
        protected Order order;


        // TODO inject property in container
        public Order OrderObject
        {
            get { return order; }
            set { order = value; }
        }

        public virtual bool IsAllowed()
        {
            // TODO assigns logic here!
            return IsAllowedModify();
        }

        public abstract void Execute(OrderController.OperationContext context);


        public abstract IRestriction GetRestriction();


        protected bool IsAllowedModify()
        {
            return order.OrderStatus == OrderStatus.Draft || order.OrderStatus == OrderStatus.Current;
        }

        protected static void AddItemToOrder(OrderItem newItem, Order order, int quantity, Decimal price, int discount, PriceItem priceItem)
        {
            newItem.Order = order;
            newItem.Quantity = quantity;
            newItem.Price = price;
            newItem.Discount = discount;
            newItem.PriceItem = priceItem;
        }

    }
}